<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
*/
    function curl_post( $uri , $data ){

        return $temp_post_result;
    }
$app->get('/', function(){
    $apikey       = "5b5f3ef06ab12542896076c854e8417c";
    $url          = "http://yunpian.com/v1/sms/send.json";
    if($_GET["phone"]){
    	$encodedText  =  urlencode("【拾光通知】我是拾光，我的2.0版本（安卓/微信）正在上线，期间无法使用还请谅解。回复我：http://timepicker.cn");
    	$postString   = "apikey=$apikey&text=$encodedText&mobile=".$_GET["phone"];
    	
    	$temp_uri = $url;
        $temp_data = $postString;
        $ch = curl_init();
        curl_setopt ( $ch, CURLOPT_URL, $temp_uri );
        curl_setopt ( $ch, CURLOPT_POST, 1 );
        curl_setopt ( $ch, CURLOPT_HEADER, 0 );
        curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
        curl_setopt ( $ch, CURLOPT_HTTPHEADER, array("Expect:") );
        curl_setopt ( $ch, CURLOPT_POSTFIELDS, $temp_data );
        $temp_post_result = curl_exec ( $ch );
        curl_close ( $ch );

    	$sendTime = date("Y-m-d H:i:s");
    	$result = ["send_code"=>"1","send_time"=>$sendTime,"send_detail"=>$temp_post_result];
    }
    echo json_encode($result);
});

$app->post('/', function(){
    $apikey       = "5b5f3ef06ab12542896076c854e8417c";
    $url          = "http://yunpian.com/v1/sms/send.json";
    if($_POST["phone"]){
    	$encodedText  =  urlencode("【拾光通知】我是拾光，我的3.0新版本（安卓/微信）即将上线，近两天由于升级出现的服务无法使用，还请谅解。回复我：http://t.cn/RASJMok");
    	$postString   = "apikey=$apikey&text=$encodedText&mobile=".$_POST["phone"];
    	
    	$temp_uri = $url;
        $temp_data = $postString;
        $ch = curl_init();
        curl_setopt ( $ch, CURLOPT_URL, $temp_uri );
        curl_setopt ( $ch, CURLOPT_POST, 1 );
        curl_setopt ( $ch, CURLOPT_HEADER, 0 );
        curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
        curl_setopt ( $ch, CURLOPT_HTTPHEADER, array("Expect:") );
        curl_setopt ( $ch, CURLOPT_POSTFIELDS, $temp_data );
        $temp_post_result = curl_exec ( $ch );
        curl_close ( $ch );

    	$sendTime = date("Y-m-d H:i:s");
    	$result = ["send_code"=>"1","send_time"=>$sendTime,"send_detail"=>$temp_post_result];
    }
    echo json_encode($result);
});

	//用户
	$app->post 	('/user', 				'UserController@store');
	$app->put 	('/user/{id}', 			'UserController@update');

	//用户通知途径
	$app->get 	('/user/{id}/method', 				'UserMethodController@index');
	$app->post 	('/user/{id}/method/{mid}', 		'UserMethodController@store');
	$app->delete('/user/{id}/method/{mid}', 		'UserMethodController@destroy');
	$app->put 	('/user/{id}/method/{mid}/grade', 	'UserMethodController@updateGrade');

	//消息集
	$app->get 	('/set/id', 			'SetController@showIdByObject');
	
	$app->post 	('/set', 				'SetController@store');
	$app->get 	('/set', 				'SetController@index');
	$app->get 	('/set/{id}', 			'SetController@show');
	$app->put 	('/set/{id}', 			'SetController@update');
	$app->delete('/set/{id}', 			'SetController@destroy');

	$app->delete('/set/{id}/user/{uid}','SetController@destroyUser');

	$app->get 	('/set/{id}/message', 	'SetMessageController@index');

	//触发
	$app->get 	('/inform/check', 		'InformCheckController@index');
	$app->get 	('/message/check', 		'MessageCheckController@index');

	//通知
	$app->post 	('/inform', 			'InformController@store');
	$app->get 	('/inform/{id}', 		'InformController@show');

	$app->post 	('/inform/send', 		'InformController@send');
	$app->put 	('/inform/{id}/close', 	'InformController@close');

	$app->put 	('/inform/{id}/send', 	'InformSendController@index');
	$app->get 	('/inform/{id}/reply', 	'InformReplyController@index');

	//消息
	$app->get 	('/message', 			'MessageController@index');
	$app->get 	('/message/count', 		'MessageController@count');

	$app->post 	('/message/{id}/reply', 'MessageReplyController@store');
